package com.ckm.async;

import com.ckm.entity.StudentCourse;
import com.ckm.mapper.StudentCourseMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MessageConsumer implements MessageListener {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Autowired
    private StudentCourseMapper studentCourseMapper;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        Object object = redisTemplate.getValueSerializer().deserialize(message.getBody());
        studentCourseMapper.insert((StudentCourse) object);
        log.info("消息队列处理：{}",object);
    }
}
